package com.itheima.reggie.controller;

import com.itheima.reggie.config.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired(required = false)
    private OrderService orderService;
    @PostMapping("/subm-it")
    public R sumbit(@RequestBody Orders orders, HttpSession session){
        Long userId = (Long) session.getAttribute("user");
//        将用户id放入到order中
        orders.setUserId(userId);
        orderService.sumbit(orders);
        return R.success("提交成功");
    }
}
